package com.wonders.frame.service;
import com.gcr.util.DateUtil;
import com.gcr.util.StringUtil;
import com.wonders.frame.common.Enum.RemovedCodeEnum;
import com.wonders.frame.entity.AuthLog;
import com.wonders.frame.repository.AuthLogRepository;
import com.wonders.frame.repository.core.CoreRepository;
import com.wonders.frame.service.Core.CoreCurdService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.Date;

/**
 * @author qiu
 * @date 2020-05-13 12:25
 */
@Service
public class AuthLogService extends CoreCurdService<AuthLog> {
    Logger log = LoggerFactory.getLogger(com.wonders.frame.service.AuthLogService.class);

    @Autowired
    private AuthLogRepository repo;

    @Override
    protected CoreRepository<AuthLog> getRepository() {
        return repo;
    }

    public AuthLog save(AuthLog authLog, String userName) {
        if(StringUtil.isEmpty(authLog.getId())) {
            log.debug("add authLog");
            authLog.setRemoved(RemovedCodeEnum.AVAILABLE.getCode());
            authLog.setCrtDate(new Date());
            authLog.setCrtUser(userName);
        }
        authLog.setUpdDate(new Date());
        authLog.setUpdUser(userName);
        return repo.save(authLog);
    }

    public void deleteLog(String beginDate, String endDate){


        //repo.deleteByBEDate(beginDate,endDate);
    }

}
